package com.audaque.jadmin.common.utils;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description :这种不好，每次都要拦截
 * @FileName: WebContextFilter.java
 * @Author :WeiHui.Zhang
 * @Data : 2015年10月19日 下午2:52:04
 * @Version:V1.00
 */
public class WebContextFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		Enumeration<String> parameterNames = filterConfig.getInitParameterNames();
		while (parameterNames.hasMoreElements()) {
			String string = (String) parameterNames.nextElement();
			System.out.println(string);
		}
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		String path = req.getContextPath();
		String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path
				+ "/";
		WebUtils.setBasePath(basePath);
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {

	}

}
